
yum -y install iptables openvpn openssl lzop git curl gcc wget squid


echo '开始配置squid'
echo '在3、5级别上自动运行squid服务'
chkconfig --level 35 squid on
rm -f /etc/squid/squid.conf
echo '写入32位系统的squid配置文件-设置监听端口是808'
echo "
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/auth_user
auth_param basic children 5  
auth_param basic realm Welcome to pycredit's proxy-only web server 
#acl localhost src 127.0.0.1/32
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
acl auth_user proxy_auth REQUIRED  

via off
request_header_access X-Forwarded-For deny all
request_header_access user-agent  deny all
reply_header_access X-Forwarded-For deny all
reply_header_access user-agentdeny deny all

http_port 808

http_access allow auth_user
http_access deny all

cache_dir ufs /var/spool/squid 100 16 256 read-only
cache_mem 0 MB
coredump_dir /var/spool/squid
access_log /var/log/squid/access.log
visible_hostname ml.baidu.com
cache_mgr 123456@baidu.com
" >/etc/squid/squid.conf

echo "
squid:QYMfUupCWAWok
" >/etc/squid/auth_user
htpasswd -c /etc/squid/passwd auth_user
echo '初始化Squid'
squid -z
echo '启动Squid'
service squid start



cd /etc/openvpn/
rm -rf *
echo '开始下载项目'
git clone https://git.oschina.net/ipking/mproxy.git
echo '删除openvpn所有文件'

echo '开始解压openvpn证书和配置文件'
unzip ./mproxy/openvpn.zip
echo '并添加可执行权限'
chmod +x  *
echo '将openvpn设置为开机自启动的服务'
chkconfig openvpn on
echo '打开ip forward功能'
sed -i '/net.ipv4.ip_forward/s/0/1/g' /etc/sysctl.conf 
sysctl -w net.ipv4.ip_forward=1

echo '立即启动openvpn服务'
/etc/init.d/openvpn start

echo '正在编译mproxy'
gcc -o ./mp ./mproxy/mproxy.c

rm -rf mproxy
mv mp mproxy
echo
echo '配置iptables'
myip=`wget -O - http://up.u080.com/ip.php`
echo "
service squid restart
service openvpn restart
iptables -t nat -A POSTROUTING -s 192.66.0.0/16 -o eth0 -j MASQUERADE
iptables -A INPUT -p TCP --dport 440 -j ACCEPT
iptables -A INPUT -p TCP --dport 8080 -j ACCEPT
iptables -A INPUT -p TCP --dport 137 -j ACCEPT
iptables -A INPUT -p TCP --dport 138 -j ACCEPT
iptables -A INPUT -p TCP --dport 80 -j ACCEPT
iptables -A INPUT -p TCP --dport 3306 -j ACCEPT
iptables -A INPUT -p TCP --dport 8888 -j ACCEPT
iptables -A INPUT -p TCP --dport 808 -j ACCEPT
iptables -A INPUT -p TCP --dport 22 -j ACCEPT
iptables -A INPUT -p TCP --dport 21 -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 53 -j DNAT --to-destination $myip:440
service iptables save
service iptables restart
killall mproxy
/etc/openvpn/mproxy -l 8080 -d
" >restart.sh
chmod u+x restart.sh
sh restart.sh

